//
//  ViewController.m
//  AVFoundationDemo
//
//  Created by rubick on 2019/1/17.
//  Copyright © 2019 LG. All rights reserved.
//

#import "ViewController.h"
#import "AVFoundationTool.h"
#import "THSpeechController.h"
#import "THPlayerController.h"
#import "AudioPlayerVC.h"
#import <AVFoundation/AVFoundation.h>
#import "ShowImageVC.h"
#import "SpeechVC.h"
#import "RecordVC.h"

@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) NSArray *methodsArr;
@property (strong, nonatomic) NSArray *titleArr;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.title = @"AVFoundation";
    self.titleArr = @[@"文本转语音", @"音频", @"视频", @"元数据"];
    self.methodsArr = @[@[@"demo1", @"demo2", @"demo3"], @[@"Audio Player", @"Voice Memo"], @[@"获取视频的第一帧"], @[@"AVAssert"]];
    self.tableView.tableFooterView = [UIView new];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass([UITableViewCell class])];
}
#pragma mark - hjkl
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.titleArr.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSArray *temp = self.methodsArr[section];
    return temp.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 45.f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 25;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return self.titleArr[section];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class])];
    NSArray *temp = self.methodsArr[indexPath.section];
    cell.textLabel.text = temp[indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if(indexPath.section == 0) {
        if(indexPath.row == 0) {
            [AVFoundationTool sayWithMessage:@"天地玄黄,宇宙洪荒。I'm rubick!"];
        } else if(indexPath.row == 1) {
            THSpeechController *speechTool = [THSpeechController speechController];
            [speechTool beginConversation];
        } else if(indexPath.row == 2) {
            [self.navigationController pushViewController:[[SpeechVC alloc] init] animated:YES];
        }
    } else if(indexPath.section == 1) {
        if(indexPath.row == 0) {
            AudioPlayerVC *vc = [[AudioPlayerVC alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        } else if(indexPath.row == 1) {
            RecordVC *vc = [[RecordVC alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        }
    } else if(indexPath.section == 2) {
        if(indexPath.row == 0) {
            ShowImageVC *vc = [[ShowImageVC alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        }
    } else if(indexPath.section == 3) {
        if(indexPath.row == 0) {
            [AVFoundationTool getAssetInfo];
        }
    }
}

@end
